//获取应用实例
import pickerview from '../../../../common/view/pickerview/pickerView';
import hyType from '../../../../common/code/pickerList/hyType';
import constants from '../../../../common/Constants';
import * as cacheUtils from '../../../../model/CacheUtils';
import PickerUtils from '../../../../model/PickerUtils';
import regexUtils from '../../../../utils/RegexUtils.js'
// import *as util from '../../../../utils/UmfUtils.js';
const posUtil = require('../commonPos.js');
import { $Toptips } from '../../../../components/CompRouter';
import TimeUtils from "../../../../utils/TimeUtils";
let cacheManager = null;
const PARAM_SIZE = 1;

Page(Object.assign({
  data: {
    //缓存数据CacheStorage(CS )
    posBasisCSData: {},
    starttime: "09:00",
    endtime: "21:00",
    hyType:"标准类"
  },

  onLoad: function (options) {
    this.setData({
      storeId: options.storeId,
      // posBasisCSData: options.basisInfoData !="undefined"? JSON.parse(options.basisInfoData):"", //看第二次点进来是否还有数据
    })
    cacheManager = new cacheUtils.cacheManager()
      .init("basisPOSInfo" + options.storeId, constants.STORAGE_FUNC.POS_BAS_INFO);
    let posBasisCSData = cacheManager.getFunc();
    // if (this.data.posBasisCSData) {
    //   cacheManager.cacheFunc({ hyTpe: this.data.posBasisCSData["hyType"], preState: this.data.posBasisCSData["preState"], starttime: this.data.posBasisCSData['starttime'], endtime: this.data.posBasisCSData["endtime"], contrId: this.data.posBasisCSData["contrId"], remark: this.data.posBasisCSData['remark'] })  //到底怎么缓存  再看看
    //   this.setDefaultData(this.data.posBasisCSData)
    // }else 
    if (posBasisCSData) {
      // posBasisCSData.storeAddress = posBasisCSData.storeAddress ? posBasisCSData.storeAddress.join("\\"):'';
      this.setDefaultData(posBasisCSData)     
    } 
    //初始化pickerview
    this.initNormalPicker([hyType])
  },
  setDefaultData:function(res){
    this.setData({
      posBasisCSData: res,
      starttime: res.starttime ? res.starttime : "09:00",
      endtime: res.endtime ? res.endtime : "21:00",
      hyType: res.hyType ? res.hyType : "标准类"
    })
  },
  /**
   * 缓存统一处理
   * @param params
   * @param flag
   */
  _pageCacheStorage(params) {
    posUtil.cacheStorage({
      "cacheManager": cacheManager,
      "params": params,
      "page": this,
      "pageName": "basisPOSInfo",
      "minLength": PARAM_SIZE
    }, this.data.storeId);
  },

  posBasInputEvent: function (e) {
    let paramsKey = e.currentTarget.id
    this._pageCacheStorage({ [paramsKey]: e.detail.value });
  },

  //提交表单
  basisPOSInfSubmit: function (e) {
    let formValues = e.detail.value
    let errorMsg = this._checkForm(formValues);
    posUtil.pageSubmit($Toptips, errorMsg)
  },

  bindSTimeChange: function (e) {
    this._pageCacheStorage({ starttime: e.detail.value });
    this.setData({
      starttime: e.detail.value
    })
  },
  bindETimeChange: function (e) {
    this._pageCacheStorage({ endtime: e.detail.value });
    this.setData({
      endtime: e.detail.value
    })
  },

  switch2Change: function (e) {
    this._pageCacheStorage({ preState: e.detail.value ?1:0})
  },
  //行业类别
  onNConfirmCB: function (idx, ret, code) {
    let hyTpNo = PickerUtils.getNormalCodeByHZ(hyType, ret).toString()
    this._pageCacheStorage({ hyType: ret })
    this.setData({
      hyType: ret,
    });
  },
  _checkForm: function (data) {
    let resultErrorMsg = regexUtils.regexTypeWithMsg(data["contrId"], constants.RegexTypes.CONTRID);
    if (resultErrorMsg) {
      return resultErrorMsg;
    }
    if (data["remark"]) {
      resultErrorMsg = regexUtils.regexTypeWithMsg(data["remark"], constants.RegexTypes.REMARK);
      if (resultErrorMsg) {
        return resultErrorMsg;
      }
    }

    return '';
},


}, pickerview));




